<template>
    <div>
        <el-icon>
            <User />
        </el-icon>
        <el-input v-model="userName" style="width: 240px" placeholder="请输入用户名" />
        <br>
        <el-icon>
            <Key />
        </el-icon>
        <el-input v-model="password" style="width: 240px" type="password" placeholder="请输入密码" show-password />
    </div>
    <div>
        <el-button type="primary" @click="enroll()">注册</el-button>
    </div>
</template>

<script setup>
import { showToast } from 'vant';

import axios from "axios"
import { ref } from 'vue'
import router from '@/router';
const userName = ref('')
const password = ref('')
function enroll() {
    axios.post("http://localhost:1337/api/v1/auth/reg", { userName: userName.value, password: password.value }).then(r => {
        if (r.data.code == 0) {
            showToast(r.data.data);
        }
        else if (r.data.code == 1) {
            showToast("注册成功");
            router.push(`/login`)
            userName.value = ""
            password.value = ""
        }

    })
}
</script>

<style></style>